package cong.cheng.quartz;

import org.quartz.*;
import org.quartz.impl.StdScheduler;
import org.quartz.impl.StdSchedulerFactory;


@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class TestJob {
    public static void main(String[] args) {
        JobDetail jobDetail= JobBuilder.newJob(MyJob.class)
                .withIdentity("job1","group1")
                .usingJobData("Job","jobDetail")
                .build();

        Trigger trigger= TriggerBuilder.newTrigger()
                .withIdentity("trigger1","TGroup1")
                .usingJobData("Trigger","TriggerDetail")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5)
                        .repeatForever())
                .build();

        try{
            Scheduler scheduler= StdSchedulerFactory.getDefaultScheduler();
            scheduler.scheduleJob(jobDetail,trigger);
            scheduler.start();
        }catch (SchedulerException e){
            e.printStackTrace();
        }
    }
}
